﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using W.Component;
using W.Models.DataAccess;

namespace W.Controllers
{
    public class AulasController : Controller
    {
        AulasComponent Component = new AulasComponent();
        EstadosRecursoComponent EstadoRecursoComponent = new EstadosRecursoComponent();
        //
        // GET: /Aulas/

        public ActionResult Index()
        {
            ViewBag.List = Component.Get();
            return View();
        }

        //
        // GET: /Aulas/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Aulas/Create

        public ActionResult Create()
        {
            ViewBag.EstadosRecursos = EstadoRecursoComponent.Get();
            return View();
        } 

        //
        // POST: /Aulas/Create

        [HttpPost]
        public ActionResult Create(int idEstadoRecurso, string nombre)
        {
            Component.Create(new Aulas
            {
                nombre = nombre,
                EstadosRecurso = EstadoRecursoComponent.Get(idEstadoRecurso)
            });

            return RedirectToAction("Index");
        }
        
        //
        // GET: /Aulas/Edit/5

        public ActionResult Edit(int id)
        {
            ViewBag.EstadosRecursos = EstadoRecursoComponent.Get();

            ViewBag.Entity = Component.Get(id);
            return View();
        }

        //
        // POST: /Aulas/Edit/5

        [HttpPost]
        public ActionResult Edit(Equipos Entity, int idEstadosRecurso)
        {
            Entity.EstadosRecurso = EstadoRecursoComponent.Get(idEstadosRecurso);
            Component.Update(Entity);

            return RedirectToAction("Index");
        }

        //
        // GET: /Aulas/Delete/5
 
        public ActionResult Delete(int id)
        {
            Component.Delete(id);
            return RedirectToAction("Index");
        }

        //
        // POST: /Aulas/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
